import Vue from 'vue';


let loader;

const showLoading = () => {
  if (loader) {
    hideLoading()
  }

  loader = Vue.$loading.show({
    color: 'black'
  });

  // 防止长时间的loading不结束的情况
  setTimeout(function () {
    hideLoading()
  }, 10000);
}

const hideLoading = () => {
    loader && loader.hide();
    loader = null;
}

const wxPayHrefReload = () => {
  const {href} = window.location;
  if (!Boolean(/\/\?\#/.test(href))) {
    window.location.href = href.replace(/\#/, '?#');
  }
}


const utils = {
  showLoading,
  hideLoading,
  wxPayHrefReload
}

export default utils;
